﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace ScarHelper
{
    public partial class Form1 : Form
    {
        public string OutputText;
        public Form1()
        {
            InitializeComponent();
            this.CreateButton.Click += new EventHandler(CreateButton_Click);
        }

        public void CreateButton_Click(object sender, System.EventArgs e)
        {
            int time = (int)this.Number.Value;
            string prefix = this.PrefixBox.Text;
            string suffix = this.SuffixBox.Text;
            string orig = this.InputText.Text;
            bool penabled = this.EnablePrefix.Checked;
            bool senabled = this.EnableSuffix.Checked;
            this.ProgressBar.Maximum = time;

            string addzero;

            bool standard = this.Normalnum.Checked;
            bool doublenum = this.Doublenum.Checked;
            bool triplenum = this.Triplenum.Checked;
            int numsetting;

            if (standard == true)
            {
                numsetting = 1;
            }
            else if (doublenum == true)
            {
                numsetting = 2;
            }
            else if (triplenum == true)
            {
                numsetting = 3;
            }
            else { numsetting = 1; }
        

            if (((penabled == false) && (senabled == false)) == false)
            {

                if (prefix.Length < 1 && penabled)
                {
                    MessageBox.Show("You need to put something into the Prefix or disabled it!");
                    return;
                }

                if (suffix.Length < 1 && senabled)
                {
                    MessageBox.Show("You need to put something into the Suffix or disable it!");
                    return;
                }

                if (orig.Length < 1)
                {
                    MessageBox.Show("You need to put something in the text box");
                    return;
                }
                
                int n = 0;
                string output;
                string pparse;
                string sparse;
                StreamWriter SW;
                SW = File.CreateText("OUTPUT.txt");
                while (n < time)
                {
                    if (n.ToString().Length == 1 && numsetting == 3)
                    {
                        addzero = "00";
                    }
                    else if (n.ToString().Length == 1 && numsetting == 2)
                    {
                        addzero = "0";
                    }
                    else if (n.ToString().Length == 2 && numsetting == 3)
                    {
                        addzero = "0";
                    }
                    else if (numsetting == 1)
                    {
                        addzero = "";
                    }
                    else
                    {
                        addzero = "";
                    }
                       
                    if (penabled == true && senabled == false) 
                    {
                        if ( prefix.Contains("%n") )
                        {
                            pparse = prefix.Replace("%n", addzero + n.ToString());
                            output = pparse + orig;
                        }
                        else
                        {
                            output = prefix + orig;
                        }
                    }
                    else if (penabled == false && senabled == true)
                    {
                        if (suffix.Contains("%n"))
                        {
                            sparse = suffix.Replace("%n", addzero + n.ToString());
                            output = orig + sparse;
                        }
                        else
                        {
                            output = orig + suffix;
                        }
                    }
                    else
                    {
                        if (prefix.Contains("%n"))
                        {
                            pparse = prefix.Replace("%n", addzero + n.ToString());
                            output = pparse + orig;
                        }
                        else
                        {
                            output = prefix + orig;
                        }
                        if (suffix.Contains("%n"))
                        {
                            sparse = suffix.Replace("%n", addzero + n.ToString());
                            output = output + sparse;
                        }
                        else
                        {
                            output = output + suffix;
                        }

                    }
                    SW.WriteLine(output + "\n");
                    this.ProgressBar.Value = n + 1;
                    n++;
                }



                SW.Close();
                    
            }
            else
            {
                MessageBox.Show("You need to insert data somewhere");
                return;
            }
        }

        public void WriteFile(string text)
        {
            
            
        


        }



    }
}
